<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                template="/WEB-INF/faces/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="content">
        <h:form>
            <p:dataTable var="student" value="#{adminStudentsBackingBean.students}">
                <p:column>
                    <f:facet name="header">
                        Name
                    </f:facet>
                    <h:outputText value="#{student.user.fname}" />
                </p:column>
                <p:column>
                    <f:facet name="header">
                        Mail
                    </f:facet>
                    <h:outputText value="#{student.user.email}" />
                </p:column>
                <p:column>
                    <f:facet name="header">
                        Courses
                    </f:facet>
                    <h:selectOneMenu>
                        <f:selectItems value="#{student.sCourses}" var="c" itemLabel="#{c.courseName}" />
                    </h:selectOneMenu>
                </p:column>
                <p:column>
                    <p:commandButton value="Delete" update="@form" actionListener="#{adminStudentsControllerBean.deleteStudent}">
                        <f:attribute name="student" value="#{student}"/>
                    </p:commandButton>
                </p:column>
            </p:dataTable>
            <p:panel header="New Student">
                <h:outputLabel for="username" value="Username:"/>
                <p:inputText id="username" value="#{adminStudentsBackingBean.user.login}"/>
                <h:outputLabel for="password" value="Password: "/>
                <p:inputText id="password" value="#{adminStudentsBackingBean.user.password}"/>
                <h:outputLabel for="name" value="Name: "/>
                <p:inputText id="name" value="#{adminStudentsBackingBean.user.fname}" />
                <h:outputLabel for="mail" value="Mail: "/>
                <p:inputText id="mail" value="#{adminStudentsBackingBean.user.email}"/>
                <h:outputLabel for="courses" value="Courses: " />
                <h:selectManyCheckbox id="courses" value="#{adminStudentsBackingBean.coursesId}">
                    <f:selectItems value="#{adminStudentsBackingBean.courses}" var="course" itemLabel="#{course.courseName}" itemValue="#{course.id}" />
                </h:selectManyCheckbox>
                <p:commandButton value="Add" actionListener="#{adminStudentsControllerBean.addNewStudent}" update="@form" />
            </p:panel>
        </h:form>
    </ui:define>

</ui:composition>
